home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gdb
/
gdb_18s.zoo
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-27
|
39KB
|
1,457 lines
/* Top level for GDB, the GNU debugger.
Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
GDB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the GDB General Public License for full details.
Everyone is granted permission to copy, modify and redistribute GDB,
but only under the conditions described in the GDB General Public
License. A copy of this license is supposed to have been given to you
along with GDB so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, go ahead and share GDB, but don't try to stop
anyone else from sharing it farther. Help stamp out software hoarding!
*/
#ifdef atarist
#include <file.h>
#else
#include <sys/file.h>
#endif
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#ifdef atarist
/* #include <param.h> */
#else
#include <sys/param.h>
#endif
#include "defs.h"
#include "command.h"
#include "param.h"
#ifdef SET_STACK_LIMIT_HUGE
#include <sys/time.h>
#include <sys/resource.h>
#endif
/* Version number of GDB, as a string. */
extern char *version;
/* Chain containing all defined commands. */
struct cmd_list_element *cmdlist;
/* Chain containing all defined info subcommands. */
struct cmd_list_element *infolist;
/* stdio stream that command input is being read from. */
FILE *instream;
/* Current working directory. */
char *current_directory;
/* The directory name is actually stored here (usually). */
static char dirbuf[MAXPATHLEN];
/* Nonzero if we should refrain from using an X window. */
int inhibit_windows = 0;
/* Function to call before reading a command, if nonzero.
The function receives two args: an input stream,
and a prompt string. */
void (*window_hook) ();
extern int frame_file_full_name;
void free_command_lines ();
char *read_line ();
static void initialize_main ();
void command_loop ();
static void source_command ();
void print_gdb_version ();
#ifdef atarist
static void Save_all_vectors();
static void Restore_all_vectors();
static int atari_logfile;
extern int gcc_mshort;
#endif
void really_exit();
/* gdb prints this when reading a command interactively */
static char *prompt;
/* Buffer used for reading command lines, and the size
allocated for it so far. */
char *line;
int linesize;
/* This is how `error' returns to command level. */
jmp_buf to_top_level;
return_to_top_level ()
{
quit_flag = 0;
immediate_quit = 0;
clear_breakpoint_commands ();
clear_momentary_breakpoints ();
delete_current_display ();
do_cleanups (0);
longjmp (to_top_level, 1);
}
/* Call FUNC with arg ARG, catching any errors.
If there is no error, return the value returned by FUNC.
If there is an error, return zero after printing ERRSTRING
(which is in addition to the specific error message already printed). */
int
catch_errors (func, arg, errstring)
int (*func) ();
int arg;
char *errstring;
{
jmp_buf saved;
int val;
bcopy (to_top_level, saved, sizeof (jmp_buf));
if (setjmp (to_top_level) == 0)
val = (*func) (arg);
else
{
fprintf_filtered (stderr, "%s\n", errstring);
val = 0;
}
bcopy (saved, to_top_level, sizeof (jmp_buf));
return val;
}
main (argc, argv, envp)
int argc;
char **argv;
char **envp;
{
extern void request_quit ();
int count;
int inhibit_gdbinit = 0;
int quiet = 0;
int batch = 0;
register int i;
#ifdef atarist
#ifndef JRDLIB
#if 0
extern int _unixmode;
_unixmode = 0;
#endif
_binmode(1);
#endif
#endif
quit_flag = 0;
linesize = 100;
line = (char *) xmalloc (linesize);
instream = stdin;
atari_logfile = 0;
getwd (dirbuf);
#ifdef atarist
#ifndef JRDLIB
/* adjust for getwd semantic diff */
if( (dirbuf[3] == '\0') && (dirbuf[1] == ':') &&
(
(dirbuf[2] == '\\') || (dirbuf[2] == '/')
)
)
dirbuf[2] = '\0';
#endif
#endif
current_directory = dirbuf;
#ifdef SET_STACK_LIMIT_HUGE
{
struct rlimit rlim;
/* Set the stack limit huge so that alloca (particularly stringtab
* in dbxread.c) does not fail. */
getrlimit (RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max;
setrlimit (RLIMIT_STACK, &rlim);
}
#endif /* SET_STACK_LIMIT_HUGE */
/* Look for flag arguments. */
for (i = 1; i < argc; i++)
{
if (!strcmp (argv[i], "-q") || !strcmp (argv[i], "-quiet"))
quiet = 1;
else if (!strcmp (argv[i], "-nx"))
inhibit_gdbinit = 1;
else if (!strcmp (argv[i], "-nw"))
inhibit_windows = 1;
else if (!strcmp (argv[i], "-batch"))
batch = 1, quiet = 1;
else if (!strcmp (argv[i], "-fullname"))
frame_file_full_name = 1;
#ifdef atarist
else if (!strcmp(argv[i], "-D"))
atari_debug++;
else if (!strcmp(argv[i], "-mshort"))
gcc_mshort = 1;
else if (!strcmp(argv[i], "-L"))
{
atari_logfile = 1;
}
#endif
else if (argv[i][0] == '-')
i++;
}
/* Run the init function of each source file */
#ifdef atarist
Save_all_vectors(); /* save all exception vectors */
#endif
initialize_all_files ();
initialize_main (); /* But that omits this file! Do it now */
signal (SIGINT, request_quit);
signal (SIGQUIT, SIG_IGN);
if (!quiet)
print_gdb_version ();
/* Process the command line arguments. */
count = 0;
for (i = 1; i < argc; i++)
{
register char *arg = argv[i];
/* Args starting with - say what to do with the following arg
as a filename. */
if (arg[0] == '-')
{
extern void exec_file_command (), symbol_file_command ();
extern void core_file_command (), directory_command ();
extern void tty_command ();
if (!strcmp (arg, "-q") || !strcmp (arg, "-nx")
|| !strcmp (arg, "-quiet") || !strcmp (arg, "-batch")
|| !strcmp (arg, "-fullname")
#ifdef atarist
|| !strcmp (arg, "-D")
|| !strcmp (arg, "-mshort")
|| !strcmp (arg, "-L")
#endif
)
/* Already processed above */
continue;
if (++i == argc)
fprintf_filtered (stderr, "No argument follows \"%s\".\n", arg);
if (!setjmp (to_top_level))
{
/* -s foo: get syms from foo. -e foo: execute foo.
-se foo: do both with foo. -c foo: use foo as core dump. */
if (!strcmp (arg, "-se"))
{
exec_file_command (argv[i], !batch);
symbol_file_command (argv[i], !batch);
}
else if (!strcmp (arg, "-s") || !strcmp (arg, "-symbols"))
symbol_file_command (argv[i], !batch);
else if (!strcmp (arg, "-e") || !strcmp (arg, "-exec"))
exec_file_command (argv[i], !batch);
else if (!strcmp (arg, "-c") || !strcmp (arg, "-core"))
core_file_command (argv[i], !batch);
/* -x foo: execute commands from foo. */
else if (!strcmp (arg, "-x") || !strcmp (arg, "-command")
|| !strcmp (arg, "-commands"))
source_command (argv[i]);
/* -d foo: add directory `foo' to source-file directory
search-list */
else if (!strcmp (arg, "-d") || !strcmp (arg, "-dir")
|| !strcmp (arg, "-directory"))
directory_command (argv[i], 0);
/* -cd FOO: specify current directory as FOO.
GDB remembers the precise string FOO as the dirname. */
else if (!strcmp (arg, "-cd"))
{
int len = strlen (argv[i]);
current_directory = argv[i];
if (len > 1 && current_directory[len - 1] == '/')
current_directory = savestring (current_directory, len-1);
chdir (current_directory);
init_source_path ();
}
/* -t /def/ttyp1: use /dev/ttyp1 for inferior I/O. */
else if (!strcmp (arg, "-t") || !strcmp (arg, "-tty"))
tty_command (argv[i], 0);
else
error ("Unknown command-line switch: \"%s\"\n", arg);
}
}
else
{
/* Args not thus accounted for
are treated as, first, the symbol/executable file
and, second, the core dump file. */
count++;
if (!setjmp (to_top_